package com.g2.admin.controller;

import com.g2.admin.model.po.AuthAuthorityPo;
import com.g2.admin.service.AuthAuthorityService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("auth")
@Api(tags = "Auth")
public class AuthController extends BaseController {
    @Autowired
    private AuthAuthorityService authorityService;

    @GetMapping("/list/{code}")
    public List<AuthAuthorityPo> auths(@PathVariable("code") String sysCode) {
        return authorityService.getAuthTree(sysCode);
    }

    @GetMapping("/auth/{id}")
    public AuthAuthorityPo auth(@PathVariable("id") long authId) {
        return authorityService.getAuthauthority(authId);
    }

    @PostMapping("/save")
    public void saveAuth(@RequestBody AuthAuthorityPo authorityPo) {
        if (null == authorityPo.getId()) {
            authorityService.addAuthauthority(authorityPo);
        } else {
            authorityService.updateAuthauthority(authorityPo);
        }
    }

    @PostMapping("/del/{id}")
    public void delAuth(@PathVariable("id") long authId) {
        authorityService.delAuthauthority(authId);
    }
}
